# coding=utf-8
from selenium import webdriver
from public.login import Mylogin
from public.customer import Customer #从public层下的customer文件导入Customer方法
from common.common import Common
from selenium.webdriver.common.keys import Keys
import unittest
import os
import time
import requests
class Testcontract(unittest.TestCase):

    '''
    @classmethod
    def setUpClass(self):
        self.driver = webdriver.Firefox()
        self.driver.get("http://182.92.197.48:8080/")
        self.driver.maximize_window()

    @classmethod
    def tearDownClass(self):
        self.driver.quit()
    '''


    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.get("http://182.92.197.48:8080/")
        self.driver.maximize_window()
        time.sleep(5)
        print("starttime:" + time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())))


    def tearDown(self):
        print("endTime:" + time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())))
        filedir = "D:/pycharm_git/test/screenshot/"
        if not os.path.exists(filedir):
            os.mkdir(filedir)
        screen_name = filedir + time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) + ".png"
        self.driver.get_screenshot_as_file(screen_name)
        # self.driver.quit()   #这里是退出浏览器的代码，调试的时候先注释掉，调试成功再放开


    def testcontract_01(self):
        '''测试新建合同最后提交审核'''
        Mylogin(self.driver).login()
        Customer(self.driver).customer_click()  #这里把点击客户管理封装到了public层 ，所以把下边的本来的客户管理点击的动作注释掉
        # time.sleep(10)
        # customer=self.driver.find_element_by_xpath('/html/body/div/section/header/div/div/div/a[2]/div')
        # customer.click()
        # time.sleep(10)
        self.driver.find_element_by_xpath('/html/body/div/section/section/aside/div/ul/a[8]/li/i').click()
        time.sleep(10)
        self.driver.find_element_by_css_selector('.right-container > button:nth-child(1) > span:nth-child(1)').click()
        time.sleep(10)
        now=time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[1]/div/div[1]/input').send_keys(f'{now}')
        time.sleep(5)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[2]/div/div[1]/input').send_keys(f'浩_web自动化{now}')
        time.sleep(5)
        self.driver.find_element_by_css_selector('div.el-form-item:nth-child(3)>div:nth-child(2)>span:nth-child(1)>div:nth-child(2)>div:nth-child(1)').click() #点击客户名称的加号
        time.sleep(10)
        self.driver.find_element_by_css_selector('.search-container > input:nth-child(1)').send_keys('赵一四')#在搜索框搜索“赵一四”
        time.sleep(2)
        self.driver.find_element_by_css_selector('.search-container > div:nth-child(2) > button:nth-child(1)').click()#点击搜索按钮
        time.sleep(5)                     #/html/body/div[3]/div[1]/div[2]/div/div/div[2]/div[3]/table/tbody/tr/td[1]/div/label/span/span
        self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div[2]/div/div/div[2]/div[3]/table/tbody/tr/td[1]/div/label/span/span').click() #点击要选择'赵一四‘
        time.sleep(5)
        self.driver.find_element_by_css_selector('.cr-contianer>div:nth-child(3)>button:nth-child(2)>span').click() #点击确定
        time.sleep(3)
        self.driver.find_element_by_css_selector('div.el-form-item:nth-child(4) > div:nth-child(2) > span:nth-child(1) > div:nth-child(2) > div:nth-child(1)').click() #点击商机名称的加号
        time.sleep(10)
        self.driver.find_element_by_xpath('/html/body/div[4]/div[1]/div[2]/div/div/div[2]/div[3]/table/tbody/tr/td[1]/div/label/span/span').click()# 选择商机名称的第一个
        time.sleep(5)
                                                  #el-popover-1529 > div:nth-child(1) > div:nth-child(3) > button:nth-child(2) > span:nth-child(1)
                                                  #el-popover-8548 > div:nth-child(1) > div:nth-child(3) > button:nth-child(2) > span:nth-child(1)
        self.driver.find_element_by_xpath('/html/body/div[4]/div[1]/div[3]/button[2]').click()# 点击商机名称的确定
        #上边的确定按钮的css路径一直在变就不能使用css路径，需要使用xpath路径，必须保证唯一
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[5]/div/div[1]/input').send_keys('2020-12-15')#点击选择下单时间的时间控件
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[7]/div/div/input').send_keys('2020-12-15') #点击选择合同开始时间
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[8]/div/div/input').send_keys('2023-12-15')#点击选择合同结束时间控件
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[10]/label/div/div').click() #时间框输入完后点击别的任意地方使时间框消失
        time.sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[9]/div/span/div/div').click() #点击客户签约人加号
        time.sleep(3)                      #/html/body/div[8]/div[1]/div[2]/div/div/div[1]/div[3]/input
        self.driver.find_element_by_xpath('/html/body/div[8]/div[1]/div[2]/div/div/div[1]/div[3]/input').send_keys('阴浩') #在客户签约人搜索框输入‘阴浩’
        time.sleep(3)                      #/html/body/div[8]/div[1]/div[2]/div/div/div[1]/div[3]/div/button/i
        self.driver.find_element_by_xpath('/html/body/div[8]/div[1]/div[2]/div/div/div[1]/div[3]/div/button/i').click() #点击客户签约人搜索框右侧搜索按钮
        time.sleep(3)                      #/html/body/div[8]/div[1]/div[2]/div/div/div[2]/div[3]/table/tbody/tr/td[1]/div/label/span/span
        self.driver.find_element_by_xpath('/html/body/div[8]/div[1]/div[2]/div/div/div[2]/div[3]/table/tbody/tr/td[1]/div/label/span/span').click() #勾选客户
        time.sleep(3)                     #/html/body/div[8]/div[1]/div[3]/button[2]/span
        self.driver.find_element_by_xpath('/html/body/div[8]/div[1]/div[3]/button[2]/span').click()  #点击客户签约人的确定按钮
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[10]/div/span/div/div/div').click() #点击公司签约人的加号
        time.sleep(3)                     #/html/body/div[9]/div[1]/div[1]/input
        self.driver.find_element_by_xpath("//input[@class='el-input__inner' and @placeholder='搜索成员']").send_keys('罗亚男')  #在公司签约人搜索框输入签约人名称
        time.sleep(3)
        self.driver.find_element_by_xpath("//span[text()='罗亚男']").click()  #点击勾选公司签约人
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[11]/div/div/input').send_keys(f'现在的时间是{now},这里是阴浩使用selenium自动化测试的演示合同') #输入备注信息
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[12]/div/div/div[3]/div[2]/input').click()  #点击整单折扣输入框
        time.sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[12]/div/div/div[3]/div[2]/input').clear() #清空折扣信息
        time.sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[12]/div/div/div[3]/div[2]/input').send_keys('30') #在折扣框中输入30
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[2]/div[2]/div/form/div/div/span/div/div/div').click()  #点击审核人员的加号
        time.sleep(3)
        self.driver.find_element_by_xpath("//div[@aria-hidden='false']/div/div/input[@class='el-input__inner' and @placeholder='搜索成员']").send_keys('罗亚男')  #在审核人搜索框输入审核人名称
        time.sleep(3)                     #/html/body/div[10]/div[1]/div[2]/div[1]/label/span[2]/span
        self.driver.find_element_by_xpath("//div[@aria-hidden='false']/div/div/div/label/span/span[text()='罗亚男']").click() #点击勾选审核人
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[3]/button[3]/span').click() #点击提交审核
        # 上方已经新建完客户，下边开始断言结果

        time.sleep(5)
        bt=self.driver.find_element_by_xpath('/html/body/div[1]/section/section/main/div/div/div[2]/div[2]/div[3]/table/tbody/tr[1]/td[3]/div')
        time.sleep(5)                             #/html/body/div[1]/section/section/main/div/div/div[2]/div[2]/div[5]/div[2]/table/tbody/tr[1]/td[20]/div/div
        status=self.driver.find_element_by_xpath('/html/body/div[1]/section/section/main/div/div/div[2]/div[2]/div[5]/div[2]/table/tbody/tr[1]/td[20]/div/div')
        self.assertIn('浩_web自动化',bt.text)
        self.assertIn('待审核',status.text)

    def testcontract_02(self):
        '''测试新建合同最后保存草稿'''
        Mylogin(self.driver).login()
        Customer(self.driver).customer_click()  #这里把点击客户管理封装到了public层 ，所以把下边的本来的客户管理点击的动作注释掉
        # time.sleep(10)
        # customer=self.driver.find_element_by_xpath('/html/body/div/section/header/div/div/div/a[2]/div')
        # customer.click()
        # time.sleep(10)
        self.driver.find_element_by_xpath('/html/body/div/section/section/aside/div/ul/a[8]/li/i').click()
        time.sleep(10)
        self.driver.find_element_by_css_selector('.right-container > button:nth-child(1) > span:nth-child(1)').click()
        time.sleep(10)
        now=time.strftime('%Y%m%d%H%M', time.localtime(time.time()))
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[1]/div/div[1]/input').send_keys(f'{now}')
        time.sleep(5)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[2]/div/div[1]/input').send_keys(f'浩_web自动化{now}')
        time.sleep(5)
        self.driver.find_element_by_css_selector('div.el-form-item:nth-child(3)>div:nth-child(2)>span:nth-child(1)>div:nth-child(2)>div:nth-child(1)').click() #点击客户名称的加号
        time.sleep(10)
        self.driver.find_element_by_css_selector('.search-container > input:nth-child(1)').send_keys('赵一四')#在搜索框搜索“赵一四”
        time.sleep(2)
        self.driver.find_element_by_css_selector('.search-container > div:nth-child(2) > button:nth-child(1)').click()#点击搜索按钮
        time.sleep(5)                     #/html/body/div[3]/div[1]/div[2]/div/div/div[2]/div[3]/table/tbody/tr/td[1]/div/label/span/span
        self.driver.find_element_by_xpath('/html/body/div[3]/div[1]/div[2]/div/div/div[2]/div[3]/table/tbody/tr/td[1]/div/label/span/span').click() #点击要选择'赵一四‘
        time.sleep(5)
        self.driver.find_element_by_css_selector('.cr-contianer>div:nth-child(3)>button:nth-child(2)>span').click() #点击确定
        time.sleep(3)
        self.driver.find_element_by_css_selector('div.el-form-item:nth-child(4) > div:nth-child(2) > span:nth-child(1) > div:nth-child(2) > div:nth-child(1)').click() #点击商机名称的加号
        time.sleep(10)
        self.driver.find_element_by_xpath('/html/body/div[4]/div[1]/div[2]/div/div/div[2]/div[3]/table/tbody/tr/td[1]/div/label/span/span').click()# 选择商机名称的第一个
        time.sleep(5)
                                                  #el-popover-1529 > div:nth-child(1) > div:nth-child(3) > button:nth-child(2) > span:nth-child(1)
                                                  #el-popover-8548 > div:nth-child(1) > div:nth-child(3) > button:nth-child(2) > span:nth-child(1)
        self.driver.find_element_by_xpath('/html/body/div[4]/div[1]/div[3]/button[2]').click()# 点击商机名称的确定
        #上边的确定按钮的css路径一直在变就不能使用css路径，需要使用xpath路径，必须保证唯一
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[5]/div/div[1]/input').send_keys('2020-12-15')#点击选择下单时间的时间控件
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[7]/div/div/input').send_keys('2020-12-15') #点击选择合同开始时间
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[8]/div/div/input').send_keys('2023-12-15')#点击选择合同结束时间控件
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[10]/label/div/div').click() #时间框输入完后点击别的任意地方使时间框消失
        time.sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[9]/div/span/div/div').click() #点击客户签约人加号
        time.sleep(3)                      #/html/body/div[8]/div[1]/div[2]/div/div/div[1]/div[3]/input
        self.driver.find_element_by_xpath('/html/body/div[8]/div[1]/div[2]/div/div/div[1]/div[3]/input').send_keys('阴浩') #在客户签约人搜索框输入‘阴浩’
        time.sleep(3)                      #/html/body/div[8]/div[1]/div[2]/div/div/div[1]/div[3]/div/button/i
        self.driver.find_element_by_xpath('/html/body/div[8]/div[1]/div[2]/div/div/div[1]/div[3]/div/button/i').click() #点击客户签约人搜索框右侧搜索按钮
        time.sleep(3)                      #/html/body/div[8]/div[1]/div[2]/div/div/div[2]/div[3]/table/tbody/tr/td[1]/div/label/span/span
        self.driver.find_element_by_xpath('/html/body/div[8]/div[1]/div[2]/div/div/div[2]/div[3]/table/tbody/tr/td[1]/div/label/span/span').click() #勾选客户
        time.sleep(3)                     #/html/body/div[8]/div[1]/div[3]/button[2]/span
        self.driver.find_element_by_xpath('/html/body/div[8]/div[1]/div[3]/button[2]/span').click()  #点击客户签约人的确定按钮
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[10]/div/span/div/div/div').click() #点击公司签约人的加号
        time.sleep(3)                     #/html/body/div[9]/div[1]/div[1]/input
        self.driver.find_element_by_xpath("//input[@class='el-input__inner' and @placeholder='搜索成员']").send_keys('罗亚男')  #在公司签约人搜索框输入签约人名称
        time.sleep(3)
        self.driver.find_element_by_xpath("//span[text()='罗亚男']").click()  #点击勾选公司签约人
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[11]/div/div/input').send_keys(f'现在的时间是{now},这里是阴浩使用selenium自动化测试的演示合同') #输入备注信息
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[12]/div/div/div[3]/div[2]/input').click()  #点击整单折扣输入框
        time.sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[12]/div/div/div[3]/div[2]/input').clear() #清空折扣信息
        time.sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[1]/div[2]/div/div/form/div[12]/div/div/div[3]/div[2]/input').send_keys('30') #在折扣框中输入30
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[2]/div[2]/div[2]/div/form/div/div/span/div/div/div').click()  #点击审核人员的加号
        time.sleep(3)
        self.driver.find_element_by_xpath("//div[@aria-hidden='false']/div/div/input[@class='el-input__inner' and @placeholder='搜索成员']").send_keys('罗亚男')  #在审核人搜索框输入审核人名称
        time.sleep(3)                     #/html/body/div[10]/div[1]/div[2]/div[1]/label/span[2]/span
        self.driver.find_element_by_xpath("//div[@aria-hidden='false']/div/div/div/label/span/span[text()='罗亚男']").click() #点击勾选审核人
        time.sleep(3)
        self.driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/div/div[3]/button[2]/span').click() #点击保存草稿
        # 上方已经新建完客户，下边开始断言结果

        time.sleep(5)                            #/html/body/div[1]/section/section/main/div/div/div[2]/div[2]/div[3]/table/tbody/tr[1]/td[3]/div
        bt_02=self.driver.find_element_by_xpath('/html/body/div[1]/section/section/main/div/div/div[2]/div[2]/div[3]/table/tbody/tr[1]/td[3]/div')
        time.sleep(5)                               #/html/body/div[1]/section/section/main/div/div/div[2]/div[2]/div[5]/div[2]/table/tbody/tr[1]/td[20]/div/div
        status_02=self.driver.find_element_by_xpath('/html/body/div[1]/section/section/main/div/div/div[2]/div[2]/div[5]/div[2]/table/tbody/tr[1]/td[20]/div/div')
        self.assertIn('浩_web自动化',bt_02.text)
        self.assertIn('未提交',status_02.text)



if __name__ == "__main__":
    unittest.main()
